use "data\out\estsample.dta", clear 
keep maalepktnr stratgroups elcar noncomplier Treat 
g estsample = 1 
duplicates drop maalepktnr, force 
g byte IHD = inlist(stratgroups,2,5,8,11) == 1

fmerge m:1 maalepktnr using "data\in\maalepktnr_grunnkretsincome.dta", keep(master match) nogenerate
g income = Snittprhusstand / 9.5377 

append using "data\in\JAERE revision\pre_patterns_sample.dta"

replace estsample = 0 if estsample == . 
egen estsample_max = max(estsample), by(maalepktnr)
keep if estsample_max == 1 
drop estsample estsample_max

merge m:1 dato hour using "data\in\temp_Timesdata2014_2020_inkllags", keep(master match) nogen

g consumption_all = forbruk 
g consumption_0_15 = forbruk if inrange(hour,0,15) 
g consumption_16_21 = forbruk if inrange(hour,16,21)  
g consumption_22_23 = forbruk if inrange(hour,22,23) 

g consumption_all_winter2019 = forbruk if year == 2019 & inrange(month,1,3)
g consumption_0_15_winter2019 = forbruk if inrange(hour,0,15) &  year == 2019 & inrange(month,1,3)
g consumption_16_21_winter2019 = forbruk if inrange(hour,16,21) & year == 2019 & inrange(month,1,3)
g consumption_22_23_winter2019 = forbruk if inrange(hour,22,23) & year == 2019 & inrange(month,1,3)

estpost su consumption* elcar IHD temp income noncomplier if Treat == 1
	est store Treat
estpost su consumption* elcar IHD temp income noncomplier if Treat == 0 
	est store Control
esttab Treat Control using "output\table_1.txt" ///
  , cells("mean (fmt(2)) sd (fmt(2) par)") varwidth(17) mtitles //tex replace
gunique maalepktnr 
gunique maalepktnr if Treat == 1  
gunique maalepktnr if Treat == 0 
 
